Easy Tutorial
For Competitive Exams

Placement Papers Zoho Programming Aptitude Questions

59458.When you pass an array to a method, the method receives ________ .
A copy of the array
A copy of the first element
The reference of the array
The length of the array
Explanation:
When sending an array to a method, the method receives the array's reference.
The array reference is returned when a method returns an array.
Arrays are provided to methods in the same way that regular variables are.
When we send an array as a parameter to a method, we are actually passing the memory location of the array (reference).
As a result, any modifications made to this array in the function will have an impact on the array.
59459.What is output of the following code:
public class solution{
        public static void main(String[] args){
                int[] x = {120, 200, 016 };
                for(int i = 0; i < x.length; i++)
                        System.out.print(x[i] + " ");
        }
}
120 200 16
120 200 14
120 200 016
016 is a compile error. It should be written as 16
Explanation:
016 is an octal number. The prefix 0 indicates that a number is in octal and in octal 16 is equal to 14.
59460.Choose the correct statement. Restriction on static methods are:
I. They can only call other static methods.
II. They must only access static data.
III. They cannot refer this or super in any way.
Only (I)
(I) and (II)
(II) and (III)
Only (III)
(I), (II) and (III)
59461.What is output of the following program:
public class solution{
        public static void main(String[] args){
                byte x = 127;
                x++;
                x++;
               System.out.println(x);
      }
}

-127
127
129
2
Explanation:
Range of byte data in java is -128 to 127 .
But byte data type in java is cyclic in nature
59462.Select the valid statement to declare and initialize an array.
int[] A = {}
int[] A = {1, 2, 3}
int[] A = (1, 2, 3)
int[][] A = {1,2,3}
59463.What is the value of a[1] after the following code is executed?
int[] a = {0, 2, 4, 1, 3};
for(int i = 0; i < a.length; i++)
a[i] = a[(a[i] + 3) % a.length];
0
1
2
3
4
Explanation:
Here's an explanation of the code:
1. The array a is initialized with values: {0, 2, 4, 1, 3}. 
2. The for loop iterates over each element of the array using the variable i. 
3. Inside the loop, the value of a[i] is updated using the expression a[(a[i] + 3) % a.length]. 
  (i) For i = 0, a[i] is 0. So, a[(0 + 3) % 5] becomes a[3 % 5] which is a[3] (value 1). 
 (ii) For i = 1, a[i] is 2. So, a[(2 + 3) % 5] becomes a[5 % 5] which is a[0] (value 0).  
 (iii) For i = 2, a[i] is 4. So, a[(4 + 3) % 5] becomes a[7 % 5] which is a[2] (value 4). 
 (iv) For i = 3, a[i] is 1. So, a[(1 + 3) % 5] becomes a[4 % 5] which is a[4] (value 3).  
 (v) For i = 4, a[i] is 3. So, a[(3 + 3) % 5] becomes a[6 % 5] which is a[1] (value 2).  
4. After the loop finishes, the modified array a becomes {0, 1, 4, 3, 2}. 
5. Finally, the code prints the value of a[1] using System.out.println(a[1]), which outputs 1.

Therefore, the output of the code is 1.
Share with Friends